package com.zhiyou100.loans.servlet.loan;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhiyou100.loans.model.Lendbill;
import com.zhiyou100.loans.service.LendbillService;
import com.zhiyou100.loans.service.impl.LendbillServiceImpl;

import net.sf.json.JSONObject;

@WebServlet("/LendbillAddServlet")
public class LendbillAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String loanbillid = request.getParameter("loanbillid");
		String money = request.getParameter("money");
		String lenderid = request.getParameter("lenderid");
		Lendbill lendbill = new Lendbill();
		lendbill.setLenderid(Integer.parseInt(lenderid));
		lendbill.setLoanbillid(Integer.parseInt(loanbillid));
		lendbill.setMoney(Double.parseDouble(money));
		
		LendbillService lends = new LendbillServiceImpl();
		JSONObject result=lends.add(lendbill);
		response.getWriter().println(result);
	}

}
